﻿namespace WMS6.BLL
{
    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Data.Common;
    using WMS6.Common;
    using WMS6.DataEntity;
    using WMS6.DBUtility;
    using WMS6.IDAL;
    using WMS6.DALFactory;

    public class AttachBLL : IBaseInfo
    {
        private static readonly IAttachDA attachDA = DataAccess.CreateAttachDA();
        private static readonly IAttachDetailDA attachDetailDA = DataAccess.CreateAttachDetailDA();
        private static readonly ICommonMethodDA commonMethod = DataAccess.CreateCommonMethod();
        private List<string> dataBaseID;
        private PubParasInfo pubParasInfo;

        public AttachBLL()
        {
            this.pubParasInfo = null;
        }

        public AttachBLL(string currentWH)
        {
            this.pubParasInfo = null;
            if (!string.IsNullOrEmpty(currentWH))
            {
                this.dataBaseID = commonMethod.GetDataBaseID(currentWH);
                if (this.dataBaseID == null)
                {
                    PublicMethod.GetInstance().ShowAlertMessage("C001");
                }
            }
            else
            {
                PublicMethod.GetInstance().ShowAlertMessage("C002");
            }
        }

        public AttachBLL(PubParasInfo tempPubParasInfo)
        {
            this.pubParasInfo = null;
            if (!string.IsNullOrEmpty(tempPubParasInfo.CurrentWH))
            {
                this.dataBaseID = commonMethod.GetDataBaseID(tempPubParasInfo.CurrentWH);
                if (this.dataBaseID == null)
                {
                    PublicMethod.GetInstance().ShowAlertMessage("C001", this.pubParasInfo.UserLanguage);
                }
                else
                {
                    this.pubParasInfo = new PubParasInfo();
                    this.pubParasInfo = tempPubParasInfo;
                }
            }
            else
            {
                PublicMethod.GetInstance().ShowAlertMessage("C002", this.pubParasInfo.UserLanguage);
            }
        }

        public string Delete(List<string> IDS)
        {
            throw new NotImplementedException();
        }

        public DataSet GetAllInfo()
        {
            throw new NotImplementedException();
        }

        public object GetInfoByID(string id)
        {
            throw new NotImplementedException();
        }

        public DataSet GetInfoByQueryEntity(object obj)
        {
            throw new NotImplementedException();
        }

        public string Insert(object obj)
        {
            AttachInfo attachInfo = obj as AttachInfo;
            string whLoginID = this.dataBaseID[0];
            DataBase dataBase = new DataBase();
            DbConnection conn = dataBase.connection;
            conn.Open();
            DbTransaction tran = conn.BeginTransaction();
            string strattach = string.Empty;
            try
            {
                attachInfo.UpdatedBy = attachInfo.CreatedBy;
                attachInfo.CreatedDate = DateTime.Now;
                attachInfo.UpdatedDate = DateTime.Now;
                if (attachDA.InsertAttach(dataBase, tran, attachInfo, whLoginID) > 0)
                {
                    strattach = attachInfo.AttachID;
                }
                tran.Commit();
            }
            catch (Exception ex)
            {
                tran.Rollback();
                CommonErrorHandler.ErrorHandler(ex, LogType.Error);
            }
            finally
            {
                conn.Close();
            }
            return strattach;
        }

        public string Update(object obj)
        {
            throw new NotImplementedException();
        }
    }
}

